Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync IntegrationEnrollKind #47106

Merged
merged 3 commits into from
Oct 22, 2024
Merged

Sync IntegrationEnrollKind #47106

merged 3 commits into from
Oct 22, 2024

Conversation

bernardjkim
Copy link
Contributor

@bernardjkim bernardjkim commented Oct 2, 2024

Requires https://github.com/gravitational/cloud/pull/10599

Metrics for integration enrollment does not seem to be working as expected. When I was testing the Datadog plugin enrollment it was reporting enrollment of the Machine ID Azure enrollment.

This seems to be due to the two IntegrationEnrollKind enums not being in sync.

Anyone know if we need to maintain the two separate enums instead of using just one?

@bernardjkim bernardjkim added observability Used for metrics and insight into Teleport. no-changelog Indicates that a PR does not require a changelog entry labels Oct 2, 2024
@bernardjkim
Copy link
Contributor Author

bernardjkim commented Oct 2, 2024

Hmm, would it be a bad idea to rewrite the enum values? Should we just reserve these values and start from 25?

Error: Enum value "18" on enum "IntegrationEnrollKind" changed name from "INTEGRATION_ENROLL_KIND_SERVICENOW" to "INTEGRATION_ENROLL_KIND_MACHINE_ID_AWS".
Error: Enum value "19" on enum "IntegrationEnrollKind" changed name from "INTEGRATION_ENROLL_KIND_ENTRA_ID" to "INTEGRATION_ENROLL_KIND_MACHINE_ID_GCP".
Error: Enum value "20" on enum "IntegrationEnrollKind" changed name from "INTEGRATION_ENROLL_KIND_DATADOG_INCIDENT_MANAGEMENT" to "INTEGRATION_ENROLL_KIND_MACHINE_ID_AZURE".
Error: buf found 3 breaking changes.

@Joerger
Copy link
Contributor

Joerger commented Oct 2, 2024

Anyone know if we need to maintain the two separate enums instead of using just one?

IIRC we need to have it in both the usage reporter service and the prehog service, so both enums are necessary. It looks like they were intended to be kept in sync with each other. We should definitely add a comment on both enums that this is the case.

All that really matters though is that we can map the usage event enum to the prehog enum during prehog processing:

func integrationEnrollMetadataToPrehog(u *usageeventsv1.IntegrationEnrollMetadata, userMD UserMetadata) *prehogv1a.IntegrationEnrollMetadata {
return &prehogv1a.IntegrationEnrollMetadata{
Id: u.Id,
Kind: prehogv1a.IntegrationEnrollKind(u.Kind),
UserName: userMD.Username,
}
}

Since this is no longer a 1-1 mapping, we just need to add some mapping logic for the out-of-sync values:

func integrationEnrollMetadataToPrehog(u *usageeventsv1.IntegrationEnrollMetadata, userMD UserMetadata) *prehogv1a.IntegrationEnrollMetadata {
	// Some enums are out of sync and need to be mapped manually
	var prehogKind prehogv1a.IntegrationEnrollKind
	switch u.Kind {
		case INTEGRATION_ENROLL_KIND_SERVICENOW:
			prehogKind = prehogv1a.INTEGRATION_ENROLL_KIND_SERVICENOW
		case INTEGRATION_ENROLL_KIND_ENTRA_ID:
			prehogKind = prehogv1a.INTEGRATION_ENROLL_KIND_ENTRA_ID
		case INTEGRATION_ENROLL_KIND_DATADOG_INCIDENT_MANAGEMENT:
			prehogKind = prehogv1a.INTEGRATION_ENROLL_KIND_DATADOG_INCIDENT_MANAGEMENT

                ### other cases

		default:
			prehogKind = prehogv1a.IntegrationEnrollKind(u.Kind)
	}

	return &prehogv1a.IntegrationEnrollMetadata{
		Id:       u.Id,
		Kind:     prehogKind,
		UserName: userMD.Username,
	}
}

And if you want to get these back in sync, we could reserve all of the out-of sync enums and just start counting from 26 again like you said. Then we'd just need to maintain some backwards compatibility mapping in the logic above. But IMO this probably isn't worth it, we'll be back in sync for future enums anyways and we'll need to keep this mapping logic indefinitely anyways, right?

@zmb3
Copy link
Collaborator

zmb3 commented Oct 2, 2024

@strideynet any idea what happened here?

It looks like you added some new enum variants to the cloud proto in https://github.com/gravitational/cloud/pull/6792/ with a note that the RPC handler converts this enum to a string representation, so no changes are actually needed to the handling code, but the variants were never added on the Teleport side. Was this intentional?

Edit: I see they were added to Teleport in #34985 but only in the teleport.proto and not in the usageevents.proto. What a footgun we have here.

@strideynet
Copy link
Contributor

Edit: I see they were added to Teleport in #34985 but only in the teleport.proto and not in the usageevents.proto. What a footgun we have here.

Ah yeah wow - that'll be the root of the issue here. This seems like a mistake that's a little too easy to mistake - is there a reason that one of these protos can't just reference the other one as a dependency ?

@bernardjkim
Copy link
Contributor Author

is there a reason that one of these protos can't just reference the other one as a dependency ?

Sorry, I let this PR get stale. I'll go ahead and merge this for now to fix metrics collection. We can revisit this topic in a separate PR.

@bernardjkim bernardjkim added no-changelog Indicates that a PR does not require a changelog entry and removed no-changelog Indicates that a PR does not require a changelog entry labels Oct 22, 2024
@bernardjkim bernardjkim added this pull request to the merge queue Oct 22, 2024
Merged via the queue into master with commit 28a6848 Oct 22, 2024
47 of 48 checks passed
@bernardjkim bernardjkim deleted the bernard/fix-enroll-metrics branch October 22, 2024 01:52
@public-teleport-github-review-bot

@bernardjkim See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed

bernardjkim added a commit that referenced this pull request Oct 22, 2024
* Sync IntegrationEnrollKind

* Map usage to prehog
bernardjkim added a commit that referenced this pull request Oct 22, 2024
* Sync IntegrationEnrollKind

* Map usage to prehog
github-merge-queue bot pushed a commit that referenced this pull request Oct 22, 2024
* Sync IntegrationEnrollKind

* Map usage to prehog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v15 backport/branch/v16 no-changelog Indicates that a PR does not require a changelog entry observability Used for metrics and insight into Teleport. size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants